package com.cy.基础.conllection;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * Set  无序  不可重复
 */
public class SetTest {
    @Test
    public void test() {
        Set set = new HashSet();
        set.add("中国");
        set.add("美国");
        set.add("日本");
        set.add("韩国");
        set.add("中国");
        System.out.println(set.size());
        System.out.println(set);
        for (Object o : set) {
            System.out.println(o);
        }
    }

    @Test
    public void test2() {
        Set set = new HashSet();
        set.add(new Dog("欧欧", "雪纳瑞"));
        set.add(new Dog("丫丫", "拉布拉多"));
        set.add(new Dog("菲菲", "拉布拉多"));
        set.add(new Dog("关关", "雪纳瑞"));
        System.out.println(set.size());
        for (Object o : set) {
            System.out.println(o);
        }
    }

    @Test
    public void test3() {
        Set set = new TreeSet();
        set.add("中国");
        set.add("美国");
        set.add("日本");
        set.add("韩国");
        set.add("中国");
        System.out.println(set.size());
        System.out.println(set);
        for (Object o : set) {
            System.out.println(o);
        }
    }

    /**
     * TreeSet
     */
    @Test
    public void test4() {
        Set set = new TreeSet();
        set.add(new Dog("欧欧", "雪纳瑞"));
        set.add(new Dog("丫丫", "拉布拉多"));
        set.add(new Dog("菲菲", "拉布拉多"));
        set.add(new Dog("关关", "雪纳瑞"));
        System.out.println(set.size());
        for (Object o : set) {
            System.out.println(o);
        }
    }
}
